import React, {Component} from 'react';

class App extends Component {
    a = 10;

    submit1() {
        console.log(this.a);
    }

    submit2 = () => {
        console.log(this.a);
    }

    render() {
        return (<div>
            <input/>
            {/*this.submit1 相当于 console.log(this.a); 会报错*/}
            <button onClick={this.submit1}>提交</button>
            {/*将render的this绑定给submit1，submit1内部才能用*/}
            <button onClick={this.submit1.bind(this)}>提交</button>
            {/*this.submit2 相当于 () => console.log(this.a);*/}
            <button onClick={this.submit2}>提交</button>
            <button onClick={() => this.submit2()}>提交</button>
        </div>);
    }
}

export default App;